﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FormConvertor;

namespace GTAFormConverterGUI
{
    public partial class FormConvertorUI : Form
    {
        public FormConvertorUI()
        {
            InitializeComponent();
            openFileDialog1.Filter = "Designer form|*.designer.cs";
            openFileDialog1.Multiselect = false;
            openFileDialog1.DefaultExt = "*.designer.cs";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                FormConverter convertor = new FormConverter();
                if (convertor.ReadDesigner(tbPath.Text))
                {
                    //GetResult
                    tbResult.Text = convertor.FinalCode;

                    //Refresh Warnings
                    listViewWarnings.Items.Clear();

                    foreach (KeyValuePair<int, String> curpair in convertor.warnings)
                    {

                        ListViewItem newitem = new ListViewItem(new String[] { curpair.Key.ToString(), curpair.Value });
                        
                        listViewWarnings.Items.Add(newitem);
                    }

                    if (listViewWarnings.Items.Count > 0)
                        tabpWarnings.Text = "Warnings (" + listViewWarnings.Items.Count + ")";
                    else
                        tabpWarnings.Text = "Warnings";
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message,err.GetType().ToString());
            }
        }

        private void btBrowse_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                tbPath.Text = openFileDialog1.FileName;

        }
    }
}
